package com.ch999.detect.View.dialog;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ch999.detect.R;
import com.ch999.detect.View.SelectStartDialog;
import com.ch999.detect.mode.bean.GoodsBjgz;

import java.util.List;

/**
 * Created by Administrator on 2016/12/13 0013.
 */

public class SelectParmsDialog extends SelectStartDialog implements View.OnClickListener {

    View.OnClickListener listener;
    LinearLayout llMainRoot;

    ShowMiaoShuPic mShowMiaoShuPic;
    private TextView tvTitle;

    public SelectParmsDialog(Context context, View.OnClickListener listener) {
        super(context);
        this.listener = listener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.dialog_screen_layout);

        llMainRoot = (LinearLayout) findViewById(R.id.ll_mian_root);
        mShowMiaoShuPic = new ShowMiaoShuPic(mContent);
        tvTitle = (TextView) findViewById(R.id.tv_title);
    }

    public void showDialog(List<GoodsBjgz.AttrBean.ValuesBean> values, String title) {
        show();

        if (!TextUtils.isEmpty(title)) {
            tvTitle.setText(title);
        }
        if (values == null || llMainRoot.getChildCount() > 1) {
            return;
        }

        int size = values.size();
        for (int j = 0; j < size; j++) {

            View inflate = View.inflate(mContent, R.layout.item_dialog_button_layout, null);
            Button checkBox = (Button) inflate.findViewById(R.id.btn);

            ImageView imgPic = (ImageView) inflate.findViewById(R.id.img_miaoshu);
            final GoodsBjgz.AttrBean.ValuesBean valuesBean = values.get(j);
            if (!TextUtils.isEmpty(valuesBean.getPic()) || !TextUtils.isEmpty(valuesBean.getMiaoshu())) {

                imgPic.setVisibility(View.VISIBLE);

                imgPic.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mShowMiaoShuPic.show(valuesBean.getPic(), valuesBean.getMiaoshu());
                    }
                });

            } else {

                imgPic.setVisibility(View.GONE);

            }

            checkBox.setText(valuesBean.getName());
            checkBox.setTag(j);
            checkBox.setOnClickListener(this);
            llMainRoot.addView(inflate);

        }

    }


    @Override
    public void onClick(View view) {
        if (listener != null) {
            listener.onClick(view);
        }
    }
}
